#pragma once

#include "typelib/span.h"

namespace My {

/** 
 * Class Span describes an interval [first, last)
 */
class Span : public ::span {
public:
	Span()
		{ }
	Span(int _first, int _last) : span(_first, _last)
		{ }
	Span(span const & s) : span(s)
		{ }
	int Size() const
		{ return size(); }
	bool Empty() const
		{ return empty(); }
	bool Valid() const
		{ return valid(); }
	int Bound(int v) const
		{ return bound(v); }
	bool operator == (const Span & s) const
		{ return ::span::operator == (s); }
	bool operator != (const Span & s) const
		{ return ::span::operator != (s); }
	bool Inside(int t) const
		{ return inside(t); }
	bool Inside(const Span & s) const
		{ return inside(s); }
public:
	Span & Offset(int d) {
		offset(d);
		return * this;
	}
	Span & Intersect(const Span & s) {
		//not like ::span::intersect(s)
		if (first < s.first)
			first = s.first;
		if (first > s.last)
			first = s.last;
		if (last < s.first)
			last = s.first;
		if (last > s.last)
			last = s.last;
		return * this;
	}
	Span Intersection(const Span & s) const
		{ return Span(*this).Intersect(s); }
	Span & Unite(const Span & s) {
		unite(s);
		return * this;
	}
	Span Union(const Span & s) const
		{ return Span(*this).Unite(s); }
};

} // My
